package com.liukunup.judge.impl;

import com.liukunup.distance.EditDistance;
import lombok.extern.slf4j.Slf4j;
import org.testng.Assert;
import org.testng.Reporter;

/**
 * 编辑距离判定器
 * @author Liu Kun
 * @date 2021-04-03 20:26:05
 **/
@Slf4j
public class JudgeEditDistance extends BaseJudge<String> {

    @Override
    public void doJudge(String result, Object reference, Class<?> clazzOfT) {
        String src = (String) clazzOfT.cast(reference);
        EditDistance.Text text = new EditDistance.Text(src, result);
        int minEditDistance = EditDistance.calc(text);
        log.info("Result: {}", text);
        Reporter.log(text.toString());
        Assert.assertEquals(minEditDistance, 0, "编辑距离不为0.");
    }
}